function numberOfMatches(n) {
  let totalNum = 0;
  while (n !== 1) { 
    if (n % 2 == 0) {
      n = n / 2;
      totalNum += n;
    } else {
      // 奇数的时候会抽出一个支队伍 且这支队伍不参与匹配
      n = (n - 1) / 2;
      totalNum += n;
      // 把抽出的队伍加上
      n += 1;
    }
  }
  return totalNum;
}
console.log(numberOfMatches(7));
console.log(numberOfMatches(14));